package o;

import com.huawei.appmarket.pkisign.apk.ApkFormatException;
import com.huawei.appmarket.pkisign.internal.apk.v2.V2SchemeVerifier;
import com.huawei.appmarket.pkisign.internal.apk.v2.V2SchemeVerifier.SignatureNotFoundException;
import com.huawei.appmarket.pkisign.zip.ZipFormatException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.apache.commons.codec.binary.Base64;

public abstract class dmb {

    public static class a {
        private final long ˊ;
        private final long ˋ;
        private final int ˎ;
        private final long ˏ;
        private final ByteBuffer ॱ;

        public a(long j, long j2, int i, long j3, ByteBuffer byteBuffer) {
            this.ˋ = j;
            this.ˏ = j2;
            this.ˎ = i;
            this.ˊ = j3;
            this.ॱ = byteBuffer;
        }

        public long ॱ() {
            return this.ˋ;
        }

        public long ˊ() {
            return this.ˏ;
        }

        public int ˋ() {
            return this.ˎ;
        }

        public long ˏ() {
            return this.ˊ;
        }
    }

    public static a ˏ(dmm o_dmm) throws IOException, ZipFormatException {
        dma ˏ = dmh.ˏ(o_dmm);
        if (ˏ == null) {
            throw new ZipFormatException("ZIP End of Central Directory record not found");
        }
        ByteBuffer byteBuffer = (ByteBuffer) ˏ.ˏ();
        long longValue = ((Long) ˏ.ˊ()).longValue();
        byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
        long ˎ = dmh.ˎ(byteBuffer);
        if (ˎ > longValue) {
            throw new ZipFormatException("ZIP Central Directory start offset out of range: " + ˎ + ". ZIP End of Central Directory offset: " + longValue);
        }
        long ॱ = dmh.ॱ(byteBuffer);
        long j = ˎ + ॱ;
        if (j <= longValue) {
            return new a(ˎ, ॱ, dmh.ˏ(byteBuffer), longValue, byteBuffer);
        }
        throw new ZipFormatException("ZIP Central Directory overlaps with End of Central Directory. CD end: " + j + ", EoCD start: " + longValue);
    }

    public static dma<dmm, Long> ˋ(dmm o_dmm) throws IOException, ZipFormatException, SignatureNotFoundException {
        return V2SchemeVerifier.ˎ(o_dmm, ˏ(o_dmm));
    }

    public static String ॱ(dmm o_dmm) {
        String str;
        try {
            dma ˋ = dly.ˋ((dmm) ˋ(o_dmm).ˏ());
            if (ˋ == null) {
                return null;
            }
            str = new String(Base64.encodeBase64((byte[]) ˋ.ˊ()), "UTF-8");
            return str;
        } catch (IOException e) {
            Logger.e("ApkUtils", e.getMessage());
            str = null;
        } catch (ZipFormatException e2) {
            Logger.e("ApkUtils", e2.getMessage());
            str = null;
        } catch (SignatureNotFoundException e3) {
            try {
                a ˏ = ˏ(o_dmm);
                str = new String(Base64.encodeBase64(dly.ˊ(o_dmm, ˏ.ॱ(), dmc.ˋ(o_dmm, ˏ))), "UTF-8");
            } catch (ZipFormatException e4) {
                throw new IllegalArgumentException("Invalid APK format");
            } catch (ApkFormatException e5) {
                throw new IllegalArgumentException("Invalid APK format");
            } catch (IOException e6) {
                throw new IllegalArgumentException("Cannot access APK");
            }
        }
    }
}
